//
//  ShippedCell.m
//  wtshoppingcite
//
//  Created by TW on 14-12-11.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "ShippedCell.h"

@implementation ShippedCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100, 80)];
    [self.contentView addSubview:_iconImage];
    
    _titleLabel = [self createLabelWithFrame:CGRectMake(_iconImage.right + 8, _iconImage.top, kWidth-120, 20) text:@"" font:16.0f textAli:NSTextAlignmentLeft textColor:MAIN_BLACK_COLOR];
    [self.contentView addSubview:_titleLabel];
    
    _subTitleLabel = [self createLabelWithFrame:CGRectMake(_titleLabel.left, _titleLabel.bottom, kWidth-120, 40) text:@"" font:15.0f textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    [self.contentView addSubview:_subTitleLabel];
    
    _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(_subTitleLabel.left, _subTitleLabel.bottom +10, 8, 8)];
    [_iconView setImage:[UIImage imageNamed:@"money_code"]];
    [self.contentView addSubview:_iconView];
    
    _totalLabel = [self createLabelWithFrame:CGRectMake(_iconView.right+2, _subTitleLabel.bottom +5, 120, 20) text:@"" font:15.0f textAli:NSTextAlignmentLeft textColor:UIColorFromRGB(0x9fa0a0)];
    [self.contentView addSubview:_totalLabel];
    
    
    _payOrder = [[UIButton alloc]initWithFrame:CGRectMake(0, _subTitleLabel.bottom +5, 60, 25)];
    _payOrder.right = kWidth - 10;
    [_payOrder setBackgroundImage:[UIImage imageNamed:@"register_select"] forState:UIControlStateNormal];
    [_payOrder setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_payOrder setFont:[UIFont systemFontOfSize:12.0f]];
    [_payOrder setTitle:@"确认收货" forState:UIControlStateNormal];
    [_payOrder addTarget:self action:@selector(finishAction) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_payOrder];
    
}

-(void)finishAction{
    
    if([self.delegate respondsToSelector:@selector(finishShippedCell:)]){
        [self.delegate finishShippedCell:self.myOrderModel];
    }
    
}


-(void)setMyOrderModel:(MyOrderModel *)myOrderModel{
    
    if (_myOrderModel != myOrderModel) {
        
        _myOrderModel = myOrderModel;
        
        MyOrderItems *myOrderItems = [[MyOrderItems alloc]initWithMyOrderItemInfo:[myOrderModel.orderItems objectAtIndex:0]];
        
        [_iconImage setImageWithURL:[NSURL URLWithString:myOrderItems.mainImgPath] placeholderImage:[UIImage imageNamed:@"all_defalutImage"]];
        _subTitleLabel.text = myOrderItems.descp;
        _titleLabel.text = myOrderItems.productName;
        _totalLabel.text = myOrderItems.salePrice;
    }
    
}


-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.backgroundColor = [UIColor clearColor];
    return label;
}


@end
